package com.gz.lot.user.service;

import com.gz.lot.user.User;
import com.gz.lot.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public Boolean register(User user) {

        // 强制设置不能指定的参数为null
        user.setId(null);
        // 添加到数据库
        boolean b = this.userMapper.insertSelective(user) == 1;
        //boolean b = this.userMapper.registerUser(user.getUsername(),user.getPassword()) == 1;
        return b;
    }

    public List<User> queryUserList() {
        return this.userMapper.selectAll();
    }

    public Boolean login(User user) {
        User result = this.userMapper.selectUserByName(user.getUsername());
        if (result != null && result.getPassword().equals(user.getPassword())){
            System.out.println("登录成功！");
            return true;
        }
        System.out.println("登录失败");
        return false;
    }
}
